package com.zdp.controller;

import com.zdp.domain.SkillGoods;
import com.zdp.service.SkillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author sesshomaru
 * @date 2021/7/19
 */
@RestController
public class ProductController {

    @Autowired
    private SkillGoodsService skillGoodsService;

    // 根据商品id从缓存中获取商品信息
    @GetMapping("/product/{productId}")
    public SkillGoods getProduct(@PathVariable Long productId) {
        System.out.println("调用商品服务");
        return skillGoodsService.queryProduct(productId);
    }

    // 当缓存中商品库存为0时，同步修改数据库中的数据
    @PostMapping("/product")
    public String update(@RequestBody SkillGoods skillGoods) {
        skillGoodsService.update(skillGoods);
        return "更新库存成功";
    }
}
